package org.gws.alaska.metamodel.builder

import java.util.Iterator;
import java.util.Map;

import org.gws.alaska.metamodel.uml.AlaskaProfileBuilder;
import org.gws.alaska.metamodel.uml.impl.AlaskaModelManagerFactory;
import org.gws.alaska.metamodel.validator.AlaskaModelSyntaxValidator;

import groovy.util.BuilderSupport;
import groovy.util.Node;

class AlaskaMetaModel extends BuilderSupport implements AlaskaMetaModelBuilder {

	AlaskaProfileBuilder modelBuilder = null;
	AlaskaModelSyntaxValidator modelValidator = null;
	def Node rootNode = null;
	def List<Node> stereoNodes;
	public static AlaskaMetaModel newInstance(){
		return new AlaskaMetaModel();
	}

	public AlaskaMetaModel() {
		modelBuilder = AlaskaModelManagerFactory.instance.getProfileBuilder()
		modelValidator = AlaskaModelManagerFactory.instance.getProfileValidator();
	}


	@Override
	protected void setParent(Object parent, Object child) {
	}
	protected Node getCurrentNode(){
		return (Node)getCurrent();
	}

	@Override
	protected Object createNode(Object name) {

		if(name == "model"){
			throw new Exception("Model name is mandatory")
		}
		return new Node(getCurrentNode(), name);
	}

	@Override
	protected Object createNode(Object name, Object value) {

		def node =  new Node(getCurrentNode(), name, value);
		if(name == "model"){
			rootNode =node;
		}
		return node;
	}

	@Override
	protected Object createNode(Object name, Map attributes) {
		def node =  new Node(getCurrentNode(), name, attributes);
		if(name == "model"){
			rootNode = node;
		}
		return node;
	}

	@Override
	protected Object createNode(Object name, Map attributes, Object value) {
		return new Node(getCurrentNode(), name, attributes, value);
	}

	@Override
	public void serialize() {
	}

	@Override
	public void validate() {
		modelValidator.validateStaticModel(rootNode);
	}

	@Override
	public void generate() {
	}

	@Override
	public void importsMetaModel() {
	}
}

